﻿using DeviceManager.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DeviceManager.Login
{
    /// <summary>
    /// Window_UserLogin.xaml 的交互逻辑
    /// </summary>
    public partial class Window_UserLogin : Window
    {
        public Window_UserLogin()
        {
            InitializeComponent();

            ImageBrush berriesBrush = new ImageBrush();
            

            this.Loaded += Window_UserLogin_Loaded;
        }

        private void Window_UserLogin_Loaded(object sender, RoutedEventArgs e)
        {
            tb_userName.Focus();
        }

        /// <summary>
        /// 取消登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        /// <summary>
        /// 登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string userName = tb_userName.Text;
            string userPwd = tb_userPwd.Password;
            if (string.IsNullOrEmpty(userName))
            {
                MessageBox.Show("请输入用户名");
                return;
            }
            if (string.IsNullOrEmpty(userPwd))
            {
                MessageBox.Show("请输入用户密码");
                return;
            }
            if (LoginManager.GetMng().UserLogin(userName, userPwd))
            {
                //this.DialogResult = false;
                this.Close();
            }
            else
            {
                MessageBox.Show("您输入的用户名和密码不匹配,请检查!");
            }
        }

        private void tb_userPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key == Key.Enter)
            {
                Button_Click_1(null, null);
            }
        }
    }
}
